package com.example.picturestorage.config;

import com.example.picturestorage.interceptor.MyMVCInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.*;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private MyMVCInterceptor myMVCInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptor = registry.addInterceptor(myMVCInterceptor);
        interceptor.addPathPatterns("/testRedirect");
        interceptor.excludePathPatterns("/test");
        interceptor.order(1);
    }


    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //和页面有关的静态目录都放在项目的static目录下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //上传的图片在D盘下的OTA目录下，访问路径如：http://localhost:8080/xxx.jpg
    }*/

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //和页面有关的静态目录都放在项目的static目录下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/","D:\\Work\\Projects\\GitProjects\\picture-storage\\src\\main\\resources\\static\\imgs");
        //上传的图片在D盘下的OTA目录下，访问路径如：http://localhost:8080/xxx.jpg
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/index").setViewName("index");
        registry.addViewController("/testFloatAndClear").setViewName("testFloatAndClear");
        registry.addViewController("/test").setViewName("test");
    }

    /*@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SecurityHandlerInterceptor())
    }*/

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }


}
